package app.common.utils.wdt.sdk;

import app.common.utils.wdt.sdk.api.goods.GoodsAPI;
import app.common.utils.wdt.sdk.api.goods.dto.GoodsSearchRequest;
import app.common.utils.wdt.sdk.api.goods.dto.GoodsSearchResponse;
import app.common.utils.wdt.sdk.impl.ApiFactory;
import app.common.utils.wdt.sdk.impl.DefaultClient;

public class Goods
{
	public static void main(String[] args)
	{
		//
		// Client client = DefaultClient.get("wdtapi3", "test", "test");
		Client client = DefaultClient.get("wdterp30", "http://192.168.1.41:30000/", "POS",
				"c1fbdd70132de9300d23a05a5f63e150:cc169a95acdaa9ffaed4e9d59f93efaa");
		GoodsAPI goodsApi = ApiFactory.get(client, GoodsAPI.class);

		GoodsSearchTest(goodsApi);
	}

	private static void GoodsSearchTest(GoodsAPI goodsApi)
	{
		GoodsSearchRequest request = new GoodsSearchRequest();
		request.setSpecNo("daba3");
		GoodsSearchResponse response = goodsApi.search(request, new Pager(10, 0, true));

		if (response.getTotal() == null || response.getTotal() == 0)
		{
			System.out.println("No eligible results!");
			return;
		}

		System.out.println("total: " + response.getTotal());
		for (GoodsSearchResponse.GoodsSearchGoodsDto goodsDto : response.getGoodsInfos())
		{
			System.out.print("goods no:" + goodsDto.getGoodsNo() + " modified : " + goodsDto.getGoodsModified());
			for (GoodsSearchResponse.GoodsSearchSpecDto specDto : goodsDto.getSpecDtos())
			{
				System.out.println(" spec no:" + specDto.getSpecNo() + " modified : " + specDto.getSpecModified());
			}
		}
	}
}
